<?php
namespace Realisation\Command;

use Symfony\Component\Console\Command\Command;
use Symfony\Component\Console\Input\InputArgument;
use Symfony\Component\Console\Input\InputInterface;
use Symfony\Component\Console\Output\OutputInterface;

/**
 * Description of ProcessRun
 *
 * @author pahhan
 */
class ProcessRun extends Command
{
    protected function configure()
    {
        $this
            ->setName('process:run')
            ->setDescription('Start process execution for given url id')
            ->addArgument('id', InputArgument::REQUIRED, 'Url id?')
        ;
    }

    protected function execute(InputInterface $input, OutputInterface $output)
    {
        $app = \Realisation\App::getInstance();

        $up = new \Realisation\UrlProvider($app['db']);
        $url = $up->getUrl($input->getArgument('id'));

        $processor = new \Realisation\Processor($url);

        $pb = new \Realisation\ProcessBuilder();
        $process = $pb->build($url->getKey());
        $output->writeln('Execution begin for url '.$url->getId());
        $processor->execute($process);
        $output->writeln('Execution end for url '.$url->getId());
    }
}

